<?php

/**
 * This is the model class for table "tbl_classes".
 *
 * The followings are the available columns in table 'tbl_classes':
 * @property integer $class_id
 * @property string $class_code
 * @property string $teacher_id
 * @property integer $subject_id
 * @property integer $course_id
 * @property string $class_detail
 * @property string $date_from
 * @property string $date_to
 */
class Classes extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Classes the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_classes';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('class_code, teacher_id, subject_id, course_id, date_from', 'required'),
			array('subject_id, course_id', 'numerical', 'integerOnly'=>true),
			array('class_code, teacher_id', 'length', 'max'=>128),
			array('class_detail, date_to', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('class_id, class_code, teacher_id, subject_id, course_id, class_detail, date_from, date_to', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'class_id' => 'Class',
			'class_code' => 'Class Code',
			'teacher_id' => 'Teacher',
			'subject_id' => 'Subject',
			'course_id' => 'Course',
			'class_detail' => 'Class Detail',
			'date_from' => 'Date From',
			'date_to' => 'Date To',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('class_id',$this->class_id);
		$criteria->compare('class_code',$this->class_code,true);
		$criteria->compare('teacher_id',$this->teacher_id,true);
		$criteria->compare('subject_id',$this->subject_id);
		$criteria->compare('course_id',$this->course_id);
		$criteria->compare('class_detail',$this->class_detail,true);
		$criteria->compare('date_from',$this->date_from,true);
		$criteria->compare('date_to',$this->date_to,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}